def count(str):
    num_digits = 0  # 数字的个数
    num_letters = 0  # 字母的个数
    num_spaces = 0  # 空格的个数
    num_others = 0  # 其他字符的个数

    for char in str:
        if char.isdigit():
            num_digits += 1
        elif char.isalpha():
            num_letters += 1
        elif char.isspace():
            num_spaces += 1
        else:
            num_others += 1

    return num_digits, num_letters, num_spaces, num_others


# 测试代码
if not count(''):
    print('测试成功')

if count('12abAB [$ ') == (2, 4, 1, 2):
    print('测试成功')
else:
    print('测试失败')


